package se.djupfeldt.oscar.logbook.datasource;

import org.apache.log4j.Logger;

public class SentenceInjector extends DataSource {
    private boolean run = true;
    private String[] sentences = {"$GPGGA,184333.07,1929.439,S,02410.387,E,1,04,2.8,1000.00,M,-33.9,M,,0000*65",
	    "$GPGLL,1929.420,S,02410.393,E,184334.07,A,A*71",
	    "$GYRO,500,0,700,10",
	    "$LIGHT,100"};
    
    public SentenceInjector() {
	super();
//	LinkedList<String> s = new LinkedList<String>();
//	for (double i = 0; i < 2*Math.PI; i += 0.05) {
//	    s.add("$LIGHT," + (int)((Math.sin(i) + 1) * 100) );
//	}
//	
//	sentences = s.toArray(sentences);
    }

    @Override
    protected void runLoop() {
	Logger.getLogger(getClass()).info("NMEA Injector started.");
	while (run) {
	    for (String sentence : sentences) {
		list.add(sentence);
		try {
		    Thread.sleep(1000);
		} catch (InterruptedException e) {
		    // TODO Auto-generated catch block
		    e.printStackTrace();
		}
	    }
	}
    }
}
